﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_RoyalItemRepayDtls : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private IRoyalItemRepayDetailBLL dtlsBLL = new RoyalItemRepayDetailBLL();
        private IMasGenderBLL genderBLL = new MasGenderBLL();

        private RadComboBox cmbRoyalItem, cmbGender;
        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            cmbRoyalItem = (RadComboBox)cbRoyalItem.FindControl("cbRoyalItem");
            cmbGender = (RadComboBox)cbGender.FindControl("cbGender");

            txtAmount.Attributes.Add("onkeypress", "return isNumberKeyDotComma(event)");

            if (Session.Keys.Count == 0)
                lblRepaySeq.Text = "0";
            else
                lblRepaySeq.Text = Session["ParentSeq"].ToString();

            if (DataItem != null)
            {
                cbRoyalItem.ListRoyalItemComboBox();
                cbGender.ListGenderComboBox();

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblRepayDtlsSeq.Text = DataBinder.Eval(DataItem, "Sequence").ToString();
                    cmbRoyalItem.SelectedValue = DataBinder.Eval(DataItem, "RoyalItems.Sequence").ToString();
                    cmbGender.SelectedValue = DataBinder.Eval(DataItem, "Gender.Sequence").ToString();
                    txtAmount.Text = DataBinder.Eval(DataItem, "Amount").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "Remarks").ToString();
                }
                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }

        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            string RepayDtlsSeq = lblRepayDtlsSeq.Text.Trim();
                
            dtlsBLL.Insert(Int32.Parse(lblRepaySeq.Text.Trim())
                    , cmbRoyalItem.SelectedValue
                    , cmbGender.SelectedValue
                    , decimal.Parse(txtAmount.Text.Trim())
                    , txtRemarks.Text.Trim()
                    , ssMng.EmpSeqI);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            dtlsBLL.Update(Int32.Parse(lblRepayDtlsSeq.Text.Trim())
                    , Int32.Parse(lblRepaySeq.Text.Trim())
                    , cmbRoyalItem.SelectedValue
                    , cmbGender.SelectedValue
                    , decimal.Parse(txtAmount.Text.Trim())
                    , txtRemarks.Text.Trim()
                    , ssMng.EmpSeqI);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}